{% extends "admin/base.html" %}
{% from 'macro/form.html' import form_field %}
{% block title %}产品管理{% endblock %}
{% block content %}
    <style type="text/css">
        .hide {
            display: none;
        }
    </style>
    <div class="pace  pace-inactive">
        <div class="pace-progress" data-progress-text="100%" data-progress="99" style="width: 100%;">
            <div class="pace-progress-inner"></div>
        </div>
        <div class="pace-activity"></div>
    </div>
    <div id="wrapper">
        {% include 'admin/admin_nav.html' %}
        <div id="page-wrapper" class="gray-bg dashbard-1">
            <div class="row border-bottom">
                {% include 'admin/header_nav.html' %}
            </div>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>数据表格</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="#">主页</a>
                        </li>
                        <li>
                            <a>表格</a>
                        </li>
                        <li>
                            <strong>数据表格</strong>
                        </li>
                    </ol>

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="ibox float-e-margins">
                                <div class="ibox-title">
                                    <h5>产品管理</h5>

                                    <div class="ibox-tools">
                                        <a class="collapse-link">
                                            <i class="fa fa-chevron-up"></i>
                                        </a>
                                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                                            <i class="fa fa-wrench"></i>
                                        </a>
                                        <ul class="dropdown-menu dropdown-user">
                                            <li><a href="form_basic.html#">选项1</a>
                                            </li>
                                            <li><a href="form_basic.html#">选项2</a>
                                            </li>
                                        </ul>
                                        <a class="close-link">
                                            <i class="fa fa-times"></i>
                                        </a>
                                    </div>
                                </div>
                                <div class="ibox-content">
                                    <form class="form-horizontal m-t" method="post" id="commentForm"
                                          novalidate="novalidate">
                                        {{ form.csrf_token }}


                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">名称：</label>

                                            <div class="col-sm-8">

                                                <input id="name" name="name" minlength="2" type="text"
                                                       class="form-control" value="{{ form.name.data }}" required=""
                                                       aria-required="true">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">图片：</label>

                                            <div class="col-sm-8">

                                                {% set image_url="/static/images/"+  form.image.data %}

                                                <img src="{{ image_url }}"
                                                     style="margin-top: 10px;max-width: 400px;width: 100%;"
                                                     class=" {% if not  form.image.data %}hide{% endif %} imageview">
                                                <input type="file" name="" class="form-control " id="index_image">
                                                <input type="text" name="image" id="image" style="display: none"
                                                       value="{{ form.image.data }}">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">年度收益：</label>

                                            <div class="col-sm-8">
                                                <input id="year_income" type="text" class="form-control"
                                                       name="year_income"
                                                       required="" aria-required="true"
                                                       value="{{ form.year_income.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">胜算率：</label>

                                            <div class="col-sm-8">
                                                <input id="win_odds" type="text" class="form-control" name="win_odds"
                                                       required="" aria-required="true"
                                                       value="{{ form.win_odds.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">当月收益：</label>

                                            <div class="col-sm-8">
                                                <input id="month_income" type="text" class="form-control"
                                                       name="month_income"
                                                       required="" aria-required="true"
                                                       value="{{ form.month_income.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">平均每次盈利：</label>

                                            <div class="col-sm-8">
                                                <input id="once_average_income" type="text" class="form-control"
                                                       name="once_average_income"
                                                       required="" aria-required="true"
                                                       value="{{ form.once_average_income.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">最大回撤：</label>

                                            <div class="col-sm-8">
                                                <input id="max_return" type="text" class="form-control"
                                                       name="max_return"
                                                       required="" aria-required="true"
                                                       value="{{ form.max_return.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">平均每次亏损：</label>

                                            <div class="col-sm-8">
                                                <input id="once_average_lost" type="text" class="form-control"
                                                       name="once_average_lost"
                                                       required="" aria-required="true"
                                                       value="{{ form.once_average_lost.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">链接：</label>

                                            <div class="col-sm-8">
                                                <input id="url" type="url" class="form-control" name="url"
                                                       required="" aria-required="true" value="{{ form.url.data }}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-3">
                                                <button class="btn btn-primary" type="submit">提交</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="wrapper wrapper-content animated fadeInRight">

            </div>
        </div>
    </div>
    <script type="text/javascript" src="{{ static('plupload/js/plupload.full.min.js') }}"></script>
    <script type="text/javascript">

        $(function () {
            var uploader = new plupload.Uploader({
                browse_button: 'index_image',
                url: "/upload_image",
                multipart_params: {
                    'csrf_token': "{{ csrf_token() }}"
                }
            });

            uploader.init();

            // 文件添加后立即上传
            uploader.bind('FilesAdded', function (up, files) {
                plupload.each(files, function (file) {
                    uploader.start();
                });
            });

            // 上传项目图片
            uploader.bind('FileUploaded', function (up, file, info) {
                var base = '/static/images/';
                var response = $.parseJSON(info.response);
                if (response.status == 'ok') {
                    $(".imageview").removeClass("hide").attr("src", base + response.name);
                    $("#image").val(response.name);
                } else {
                    $('.upload-error-info').text(response.error);
                }
            });
        })

    </script>
{% endblock %}